//
//  JackStringExtension.swift
//  SparklingPets
//
//  Created by iOS-Czz on 2023/10/26.
//

import Foundation
extension String {
    
}
extension NSMutableAttributedString {
    
}
extension NSAttributedString {
    static func coloredString(originalText: String, coloredSubText: String, colorForColoredText: UIColor) -> NSAttributedString {
        let attributedString = NSMutableAttributedString(string: originalText)
        
        // 查找coloredSubText在原始文本中的范围
        if let range = originalText.range(of: coloredSubText) {
            let nsRange = NSRange(range, in: originalText)
            
            // 设置coloredSubText的颜色
            attributedString.addAttribute(.foregroundColor, value: colorForColoredText, range: nsRange)
        }
        
        return attributedString
    }
}
